using System;
using System.Drawing;
using System.Windows.Forms;
using BLL;
using Common;
using Model;

namespace UI {
    public partial class FrmManagerLogin : Form {
        private UserBLL _userBll = UserBLL.GetUserInfoBLL();
        
        public FrmManagerLogin() {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        //登录
        private void loginBtn_Click(object sender, EventArgs e) {
            string name = unameTextBox.Text.Trim();
            string pwd = pwdTextBox.Text.Trim();
            InfoLabel.ForeColor = Color.Red;
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(pwd)) {
                InfoLabel.Text = "username or password is empty";
                return;
            }

            Result<User> result = _userBll.ManagerLogin(new User() {
                UserName = name,
                Password = pwd
            });

            if (!result.IsSuccess) {
                InfoLabel.Text = result.Message;
                return;
            }
            
            MessageBox.Show("login success");
            this.Hide();
            new FrmUserInfoOperation(this).Show();
        }

        private void FrmLogin_FormClosing(object sender, FormClosingEventArgs e) {
            
        }
    }
}